package com.fengmi.goods.controller;


import com.fengmi.entity.goods.MallGoods;
import com.fengmi.entity.goods.MallGoodsSku;
import com.fengmi.entity.vo.CatHotVo;
import com.fengmi.entity.vo.ResultVO;
import com.fengmi.goods.service.IMallGoodsService;
import com.fengmi.goods.service.IMallGoodsSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小马
 * @since 2021-10-12
 */
@RestController
@RequestMapping("/goods")
@RefreshScope
public class MallGoodsController {
    @Value("${goods.hot.topn}")
    private Integer topn;
    @Autowired
    private IMallGoodsService mallGoodsService;
    @Autowired
    private IMallGoodsSkuService goodsSkuService;
    @RequestMapping("findCatHotGoods")
    public List<CatHotVo> findCatHotGoods(){
        return mallGoodsService.findGoodsByCatId(topn);
    }

    @RequestMapping("findGoods")
    public List<MallGoods> findGoods(){
        return mallGoodsService.selectGoodsSpuInfo();
    }

    @RequestMapping("audit/{spuId}")
    public ResultVO audit(@PathVariable String spuId){
        return mallGoodsService.audit(spuId);
    }

    @RequestMapping("findGoodsDetail/{spuId}")
    public MallGoods findGoodsDetail(@PathVariable String spuId){
        return mallGoodsService.findGoodsDetail(spuId);
    }



    @RequestMapping("findSkuById/{skuId}")
    public MallGoodsSku  findSkuById(@PathVariable String skuId){
        return goodsSkuService.getById(skuId);
    }

}
